package com.guigu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.guigu.bean.Idea;
import com.guigu.bean.IdeaExample;
import com.guigu.bean.IdeaExample.Criteria;
import com.guigu.dao.IdeaMapper;

/**
 * @author wangzibin
 *灵感的CRUD
 *服务层
 */
@Service
public class IdeaServices {

	@Autowired
	IdeaMapper ideaMapper;
	
	/**
	 * 日期模糊查询灵感
	 * @param vagueDate
	 * @param userId
	 * @return
	 */
	public List<Idea> getIdeasByVagueDate(String vagueDate,int userId){
		if (vagueDate==null||userId==0) {
			return null;
		}
		IdeaExample example=new IdeaExample();
		Criteria criteria=example.createCriteria();
		criteria.andIdeatimeVagueLike(vagueDate).andUseridEqualTo(userId);
		return ideaMapper.selectByExample(example);
	}
	
	/**
	 * 灵感跟据分享状态查询
	 * @param share
	 * @return
	 */
	public List<Idea> getIdeasByShare(String share){
		return ideaMapper.seleIdeasByShare(share);
	}
	
	/**
	 * 灵感保存
	 * @param idea
	 */
	public void saveIdea(Idea idea){
		ideaMapper.insertSelective(idea);
	}
	
	/**
	 * 灵感修改
	 * @param idea
	 */
	public void updateIdea(Idea idea){
		ideaMapper.updateByPrimaryKeySelective(idea);
	}
	
	/**
	 * 灵感删除
	 * @param ideaId
	 */
	public void deleteByIdeaId(Integer ideaId){
		ideaMapper.deleteByPrimaryKey(ideaId);
	}

	/**
	 * 返回所有灵感
	 * @param userid 
	 * @return
	 */
	public List<Idea> getAllIdeas(int userid) {
		// TODO Auto-generated method stub
		IdeaExample example=new IdeaExample();
		Criteria criteria=example.createCriteria();
		criteria.andUseridEqualTo(userid);
		return ideaMapper.selectByExample(example);
		 
	}
}
